package com.leyou.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.leyou.common.enums.ExceptionEnum;
import com.leyou.common.exception.LyException;
import com.leyou.common.utils.BeanHelper;
import com.leyou.pojo.CategoryDTO;
import org.springframework.stereotype.Service;

import com.leyou.entity.TbCategory;
import com.leyou.mapper.TbCategoryMapper;
import com.leyou.service.TbCategoryService;
//import org.springframework.util.CollectionUtils;

import java.util.List;

@Service
public class TbCategoryServiceImpl extends ServiceImpl<TbCategoryMapper, TbCategory> implements TbCategoryService{

    public List<CategoryDTO> querycategoryListById(long pid) {
        //根据pid查询
        QueryWrapper<TbCategory> wrapper = new QueryWrapper<>();

        wrapper.lambda().eq(TbCategory::getParentId, pid);
        List<TbCategory> list = this.baseMapper.selectList(wrapper);


        if (list==null || list.size()==0){
            throw new LyException(ExceptionEnum.CATEGORY_NOT_FOUND);
        }
        List<CategoryDTO> categoryDTOS = BeanHelper.copyWithCollection(list, CategoryDTO.class);
        return categoryDTOS;
    }
}
